using System;
using System.Collections.Generic;
using System.Text;

static public class serverControl
{
    public static int maxQueue = 10, posStart = 0, posEnd = 0;
    public static sinalData[] commandQueue;
    public static bool loaded = false;
    public static void init()
    {
        int i;
        if (loaded) return;
        loaded = true;
        commandQueue = new sinalData[maxQueue];
        for (i = 0; i < maxQueue; i++)
        {
            commandQueue[i] = new sinalData();
        }
    }
    static public void release()
    {
        int i;
        if (!loaded) return;
        loaded = false;
        for (i = 0; i < maxQueue; i++)
        {
            commandQueue[i] = null;
        }
        commandQueue = null;
    }
    static public bool addCommand(sinalData anew)
    {
        if ((posEnd + 1) % maxQueue == posStart)
            return false;
        commandQueue[posEnd] = anew;
        posEnd++;
        posEnd %= maxQueue;
        return true;
    }
    static public sinalData getCommand()
    {
        int oldPos = posStart;
        if (posEnd == posStart)
        {
            return null;
        }
        posStart++;
        posStart %= maxQueue;
        return commandQueue[oldPos];

    }
}
